#include "file_filter.h"
#include <regex>
#include "log.h"
#include "string_util.h"
#include "win_util.h"

bool FileFilter::Handle(const ProcessInfo &process)
{
    std::shared_ptr<ProductInfo> info = GetProcessFileProductInfo(process.fileName);
    if (info != nullptr) {
        LOG_DEBUG("product info: productName >> {}", UnicodeToUtf8(info->productName));
        for (auto &item : trustedProductNameList) {
            if (FindIgnoreCase(info->productName, item)) {
                return true;
            }
        }
    }
    std::wstring file = GetFileName(process.fileName);
    for (auto &item : trustedAppNamePatternList) {
        if (std::regex_match(file, std::wregex(item, std::regex::icase))) {
            return true;
        }
    }
    LOG_DEBUG("process {} is untrusted.", UnicodeToUtf8(process.fileName));
    return false;
}

void FileFilter::Update()
{}